<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>已有应用</title>
<script src="js/jquery-1.9.1.min.js"></script>

<script src="js/jquery.mCustomScrollbar.concat.min.js"></script>
<link href="css/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css">

<script src="js/jquery.jtip.js"></script>
<link href="css/jquery.jtip.css" rel="stylesheet" type="text/css">

<script src="js/dump.js"></script>

<script src="js/rb.js"></script>
<link href="css/rb.css" rel="stylesheet" type="text/css">
<script>
var firstwidth = (FRAMEWIDTH-FRAMEWIDTH*3/5)-30;
var secondwidth = FRAMEWIDTH-FRAMEWIDTH*2/5;
$(document).ready(function() {
	
	$(".rb_mainframe_middle").eq(0).css("width",secondwidth+"px");
	$(".rb_mainframe_middle").eq(0).css("z-index","2");
	$(".rb_mainframe_middle").eq(1).css("width",firstwidth+"px");
	$(".rb_mainframe_middle_content").mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});
	$(".rb_mainframe_middle").eq(1).mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});
	$(".rb_mainframe_middle").eq(1).css("left",secondwidth+10+"px");
	$(".rb_mainframe_middle").eq(1).css("z-index","1");
	
	getAppList();
	
	
});

//获取已有流程列表数据
function getAppList(){
	$("#report tr").not(":first").remove();
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"applicationmanager/list",
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			for (var i=0;i<json.respBody.data.length;i++){
				var iconUrl = "assets/no_img.png";
				var sysLogo;
				if (json.respBody.data[i].iconUrl.length>0){
					iconUrl = IMGURL+json.respBody.data[i].iconUrl;
				}
				if (json.respBody.data[i].platformType == "iphone"){
					sysLogo = "assets/ios_logo.png";
				}else{
					sysLogo = "assets/android_logo.png";
				}
				if (json.respBody.data[i].isValid == 0){
					$("#report").append("<tr id='"+json.respBody.data[i].id+"'><td><img class='report_tx' src='"+iconUrl+"' /></td><td>"+json.respBody.data[i].applicationName+"</td><td>"+json.respBody.data[i].versionName+"</td><td><img src='"+sysLogo+"' width='30px' height='30px' border=0/></td><td><a href=\"javascript:validApp('"+json.respBody.data[i].id+"','"+json.respBody.data[i].applicationName+"');\" id='item_"+json.respBody.data[i].id+"'>停用中</a></td><td><a href='edityy.html' onclick=\"RB.Sstrorage(true,'appId','"+json.respBody.data[i].id+"');RB.Sstrorage(true,'appName','"+json.respBody.data[i].applicationName+"')\">更新</a> <a href=\"javascript:showDeleteApp('"+json.respBody.data[i].id+"','"+json.respBody.data[i].applicationName+"')\">删除</a></td></tr>");
				}else{
					$("#report").append("<tr id='"+json.respBody.data[i].id+"'><td><img class='report_tx' src='"+iconUrl+"' /></td><td>"+json.respBody.data[i].applicationName+"</td><td>"+json.respBody.data[i].versionName+"</td><td><img src='"+sysLogo+"' width='30px' height='30px' border=0/></td><td><a href=\"javascript:disvalidApp('"+json.respBody.data[i].id+"','"+json.respBody.data[i].applicationName+"');\" id='item_"+json.respBody.data[i].id+"' style='color:blue;'>启用中</a></td><td><a href='edityy.html' onclick=\"RB.Sstrorage(true,'appId','"+json.respBody.data[i].id+"');RB.Sstrorage(true,'appName','"+json.respBody.data[i].applicationName+"')\">更新</a> <a href=\"javascript:showDeleteApp('"+json.respBody.data[i].id+"','"+json.respBody.data[i].applicationName+"')\">删除</a></td></tr>");
				}
			}
			//底部占位
			$("#report").append("<tr height='150px;'></tr>");
			//默认第一个流程选中
			$("#report tr:nth-child(2) td").css("background-color","#fbe7ce");
			$("#report tr:nth-child(2) td").css("font-weight","bold");
			getAppIdList($("#report tr:nth-child(2)").attr("id"));
			$(".rb_mainframe_middle_title").html($("#report tr:nth-child(2) td:nth-child(2)").text());
			//点击读取数据
			$("#report tr").click(function(){
				$("#report tr").each(function(){
					$(this).find("td").css("background-color","transparent");
					$(this).find("td").css("font-weight","normal");
					$("#change_mark").css("opacity","0.0");
				});
				$(this).find("td").css("background-color","#fbe7ce");
				$(this).find("td").css("font-weight","bold");
				var x=$(this).offset().top;
				var y=$(this).offset().left;
				$(this).css("top","106px");
				$(this).css("top","106px");
				$('.rb_mainframe_middle').eq(1).animate({left:0,width:0},50);
				$('.rb_mainframe_middle').eq(1).animate({left:secondwidth+10,width:firstwidth},300);
				
				getAppIdList($(this).attr("id"));
				
				var str = $(this).find("td:eq(1)").text();
				$(".rb_mainframe_middle_title").html(str);
				//这里执行刷新人员列表代码
			
			});
        },
        error: function(){
            
    	}
	});	
}
//启用流程
function validApp(id,name){
	RB.Alert("启用应用","您确定要启用'"+name+"'应用吗？","submitValidApp('"+id+"','1','"+name+"');");
}
//停用流程
function disvalidApp(id,name){
	RB.Alert("停用应用","您确定要停用'"+name+"'应用吗，停用后用户将不能使用该流程？","submitValidApp('"+id+"','0','"+name+"');");
}

//确认停用或启用应用
function submitValidApp(id,bol,name){
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"applicationmanager/isValid/"+id+"?isValid="+bol,
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			//dump(json);
			if (bol == 1){
				RB.Toast("<b>\""+name+"\"</b>流程启用成功！");				
			}else{
				RB.Toast("<b>\""+name+"\"</b>流程停用成功！");	
			}
			getAppList();
        },
        error: function(){
            alert("submitValidApp error");
    	}
	});	
}

//删除流程提示
function showDeleteApp(id,name){
	RB.Alert("删除应用确认","你确认要删除\""+name+"\"应用吗？删除后该应用将不可用！","deleteApp('"+id+"','"+name+"')");
}

//删除流程
function deleteApp(id,name){
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"applicationmanager/delete/"+id,
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			//dump(json);
			RB.Toast("删除<b>\""+name+"\"</b>流程成功！");	
			getAppList();
        },
        error: function(){
            alert("delete error");
    	}
	});	
}

//暂不支持删除应用实例
/*
//删除应用实例提示
function showDeleteAppInstances(id,flowId){
	RB.Alert("删除流程记录确认","你确认要删除该条流程记录吗？","deleteAppInstances('"+id+"','"+flowId+"')");
}
//删除应用实例
function deleteAppInstances(id,flowId){
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"defaultWorkFlow/flowInstances/delete?flowId="+id,
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			//dump(json);
			RB.Toast("<b>"+json.respMessage+"</b>");
			getFlowIdList(flowId);
        },
        error: function(){
            alert("deleteAppInstances error");
    	}
	});	
}
*/

//获取某个流程列表数据
function getAppIdList(appId){
	$("#appIdList tr:gt(0)").children().remove();
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"applicationmanager/details/"+appId,
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			if (json.respList.length<=0){
				$("#appIdList").append("<tr><td colspan='5' align='center'>该应用暂无发布记录</td></tr>");
			}else{
				for(var i=0;i<json.respList.length;i++){
					//$("#appIdList").append("<tr><td>"+json.respList[i].versionName+"</td><td>"+json.respList[i].updateTime+"</td><td>"+json.respList[i].isPublish+"</td><td><a href='javascript:showDeleteAppInstances(\""+json.respList[i].id+"\",\""+json.respList[i].applicationName+"\",\""+json.respList[i].versionName+"\")'>删除</a></td></tr>");
					$("#appIdList").append("<tr><td>"+json.respList[i].versionName+"</td><td>"+json.respList[i].updateTime+"</td><td>"+json.respList[i].isPublish+"</td></tr>");
					
				}
			}
				
        },
        error: function(){
            
    	}
	});	
}

</script>
<style type="text/css">
a{
	color 				: #ff0000;	
	text-decoration		: none;
}

a:hover{
	text-decoration		: underline;
}
.report { border-collapse:collapse;}
.report h4 { margin:0px; padding:0px;}
.report ul { margin:10px 0 10px 10px; padding:0px;}
.report ul li {
	float:left;
	width:30%;
	height:40px;
	list-style-type:none;
	padding:10px;
	font-size:15px;
}
.report ul li div {
	float:left;
	height:40px;
	line-height:40px;
	margin-left:10px;
	
}
.report ul li div:nth-child(2){
	font-weight:bold;
	width:50%;
}
.report table{ width:100%;}
.report th { background:#f2638f; color:#fff; padding:7px 15px; text-align:left;width:22%;height:30px;}
.report th:first-child {width:50px;}
.report th:nth-child(5) {width:15%;}
.report td { background:#fff none repeat-x scroll center left; color:#000; padding:20px 10px;color:#5a3c44; border-bottom:#f0f0f0 1px solid; }
.report tr.odd td { background-color:transparent; cursor:pointer;color:#837076; }
.report tr.odd td.up { background:#fbe7ce; cursor:pointer; font-weight:bold; border-top:#FFF 1px solid; color:#5a3c44; }
.report tr.odd td.color { color:#fbe7ce;}
.report div.arrow { background:transparent url(assets/arrows.png) no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
.report div.up { background-position:0px 0px;}
.report_tx{
	width:40px;
	height:40px;
	background-size:40px 40px;
	float:left;
	border-radius:20px;
	box-shadow: 3px 3px 3px #888888;
}
#appIdList th { background:#f0f0f0; color:#666; border-bottom:#cdcdcd solid 1px; padding:7px 15px; text-align:left;width:25%;height:30px;font-size:medium;}
/*
#appIdList th:last-child { width:50px;}
*/
#appIdList td { padding:10px 10px;}

.rb_mainframe_top_title_first{
	background-color:#f2638f;
	background-image:url(assets/top_bar_first_item_bg2.png);	
}

.rb_mainframe_middle_title{
	background-color:#f2638f;
}
</style>
</head>

<body onselectstart="return false"> 
<div class="rb_mainframe_top">
	<div class="rb_mainframe_top_title_first">
    	应用中心
    </div>
    <div class="rb_mainframe_top_title_second">
    	已有应用
    </div>     
    <div class="rb_mainframe_top_btn">帮助</div>
</div>
<div class="rb_mainframe_content">
    <div class="rb_mainframe_middle">
        <div class="rb_mainframe_middle_content">
            <table id="report" class="report">
                <tr>
                    <th></th>
                    <th>应用名</th>
                    <th>当前版本</th>
                    <th>平台</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>             
            </table>
        </div>
    </div>
    <div class="rb_mainframe_middle">
        <div class="rb_mainframe_middle_title">XX应用</div>
        <table id="appIdList" class="report">
        	<tr>
                <th>版本</th>
                <th>发布时间</th>
                <th>发布人</th>
            </tr>             
        </table>
    </div>
</div>

<div id="change_mark"></div>
</body>
</html>
